local skill = fk.CreateSkill {
  name = "#ling__emperor_grant_skill",
  attached_equip = "ling__emperor_grant",
}

Fk:loadTranslationTable{
  ["#ling__emperor_grant_skill"] = "丹书铁券",
  ["#ling__emperor_grant-invoke"] = "丹书铁券：是否与 %dest 拼点？若赢则此【杀】对你无效，没赢者摸一张牌",
}

skill:addEffect(fk.TargetConfirmed, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skill.name) and
      data.card.trueName == "slash" and player:canPindian(data.from)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {
      skill_name = skill.name,
      prompt = "#ling__emperor_grant-invoke::"..data.from.id,
    }) then
      event:setCostData(self, {tos = {data.from}})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local pindian = player:pindian({data.from}, skill.name)
    local winner = pindian.results[data.from].winner
    if winner == player then
      data.use.nullifiedTargets = data.use.nullifiedTargets or {}
      table.insertIfNeed(data.use.nullifiedTargets, player)
      if not data.from.dead then
        data.from:drawCards(1, skill.name)
      end
    else
      if not player.dead then
        player:drawCards(1, skill.name)
      end
      if winner == nil and not data.from.dead then
        data.from:drawCards(1, skill.name)
      end
    end
  end,
})

return skill
